//package com.xunlai.infra.permission.manager.sercurity;
//
//import org.apache.commons.collections.CollectionUtils;
//import org.springframework.security.core.GrantedAuthority;
//import org.springframework.security.core.authority.AuthorityUtils;
//import org.springframework.security.core.authority.SimpleGrantedAuthority;
//import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest;
//import org.springframework.security.oauth2.client.oidc.userinfo.OidcUserService;
//import org.springframework.security.oauth2.core.OAuth2AuthenticationException;
//import org.springframework.security.oauth2.core.oidc.OidcUserInfo;
//import org.springframework.security.oauth2.core.oidc.user.DefaultOidcUser;
//import org.springframework.security.oauth2.core.oidc.user.OidcUser;
//
//import java.util.Arrays;
//import java.util.Collection;
//import java.util.List;
//
///**
// * @author liang
// * @date 12/8/22 5:08 PM
// */
//public class EnhanceOidcUserService extends OidcUserService {
//
//    private static final String ROLE_CLAIM = "role";
//
//    @Override
//    public OidcUser loadUser(OidcUserRequest userRequest) throws OAuth2AuthenticationException {
//        OidcUser oidcUser = super.loadUser(userRequest);
//        Collection<? extends GrantedAuthority> authorities = oidcUser.getAuthorities();
//        List<String> role = oidcUser.getClaim(ROLE_CLAIM);
////        if()
//        if(CollectionUtils.isEmpty(role)){
//            return oidcUser;
//        }
//        List<GrantedAuthority> authorityList = AuthorityUtils.createAuthorityList(role.toArray(new String[0]));
//        authorityList.addAll(authorities);
//        OidcUserInfo userInfo = oidcUser.getUserInfo();
//        return new DefaultOidcUser(authorityList, oidcUser.getIdToken(), userInfo);
//    }
//}
